﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using Gao.Poker.DataPrivader.Migrations;
using Gao.Poker.Domain;

namespace Gao.Poker.DataPrivader
{
    public class PokerDbContext : DbContext
    {
        public PokerDbContext()
            : base("PokerDbContext")
        {
            //Database.SetInitializer<PokerDbContext>(new PokerInitializer());
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<PokerDbContext, Configuration>());
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            //modelBuilder.Entity<Competition>().HasMany(a => a.CompetitionLevels).WithRequired().HasForeignKey(
            //    a => a.CompetitionID).WillCascadeOnDelete(false);
            modelBuilder.Entity<SendSms>().HasMany(a => a.SendSmsMembers).WithRequired().HasForeignKey(a => a.SendSmsID);
            modelBuilder.Entity<Consumption>().HasMany(a => a.ConsumptionPrlducts).WithRequired().HasForeignKey(
                a => a.ConsumptionID);
        }
        
        public DbSet<User> User { get; set; }
        public DbSet<Member> Members { get; set; }
        public DbSet<RechargeLog> RechargeLogs { get; set; }
        public DbSet<Tables> Tableses { get; set; }
        public DbSet<Competition> Competitions { get; set; }
        public DbSet<CompetitionLevel> CompetitionLevels { get; set; }
        public DbSet<CompetitionEntry> CompetitionEntries { get; set; }
        public DbSet<Product> Products { get; set; }
        public DbSet<SendSms> SendSmses { get; set; }
        public DbSet<SendSmsMember> SendSmsMembers { get; set; }
        public DbSet<Consumption> Consumptions { get; set; }
        public DbSet<ConsumptionProduct> ConsumptionPrlducts { get; set; }
        public DbSet<Seating> Seatings { get; set; }
        public DbSet<BuyRecord> BuyRecords { get; set; }
        public DbSet<Bouns> Bounses { get; set; }
    }
}
